package com.example.spring_boot_demo.config;

import com.example.spring_boot_demo.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    //@Resource
    //private LoginInterceptor loginInterceptor;

    //@Override
    //public void addInterceptors(InterceptorRegistry registry) {
    //    // 添加拦截器 拦截所有的请求
    //    registry.addInterceptor(loginInterceptor).
    //            addPathPatterns("/**")
    //            //排除登录接口
    //            .excludePathPatterns("/user/login");
    //}

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                .allowedHeaders("*");
    }
}
